﻿namespace ImageWallControl.BrushProviders
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows.Media;

    public class ImageBrushProvider : IBrushProvider
    {
        public ImageBrushProvider()
        {
            Images = new List<ImageBrush>();
        }

        public List<ImageBrush> Images { get; set; }

        public void Initialize(Action<IEnumerable<Brush>> afterInitialize)
        {
            afterInitialize(Brushes());
        }

        public Brush GetBrush()
        {
            return Images.First();
        }

        private IEnumerable<Brush> Brushes()
        {
            while (true)
                foreach (var brush in Images)
                {
                    yield return brush;
                }
        }
    }
}